import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import '../../model/xhsskd.dart';
import '../../pages/xhss/xhssHelper.dart';
import '../../widgets/myBar.dart';
import '../../widgets/someCards.dart';

class XHSSCountPanel extends StatelessWidget {
  final List<XHSSKD> RList;
  XHSSCountPanel(this.RList);

  List<BarVal> cTime() {
    var xx = <BarVal>[];
    var yy = <BarVal>[];

    double max = 0;
    for (int i = 0; i < 4; i++) {
      int nn = 0;

      for (var a in RList) {
        if (a.TypeId == i) nn++;
      }
      if (nn > max) max = nn.toDouble();

      xx.add(BarVal(XHSSHelper.getName(i), nn.toDouble(), nn.toString() + '次'));
    }

    for (var x in xx) {
      yy.add(BarVal(x.name, x.val / max, x.label));
    }

    if (max == 0) {
      return <BarVal>[];
    }
    return yy;
  }

  List<BarVal> cTime2() {
    var xx = <BarVal>[];
    var yy = <BarVal>[];

    double max = 0;
    for (int i = 0; i < 4; i++) {
      double nn = 0;

      for (var a in RList) {
        if (a.TypeId == i) nn += a.Hours;
      }

      if (nn > max) max = nn;

      xx.add(BarVal(XHSSHelper.getName(i), nn, nn.toStringAsFixed(1) + '小时'));
    }

    for (var x in xx) {
      yy.add(BarVal(x.name, x.val / max, x.label));
    }
    if (max == 0) {
      return <BarVal>[];
    }
    return yy;
  }

  @override
  Widget build(BuildContext context) {
    if (RList == null) return new Container();
    // TODO: implement build
    return new Container(
        margin: const EdgeInsets.only(bottom: 10.0),
        child: RList.length == 0
            ? new Container()
            : SingleChildScrollView(
                child: Column(children: [
                  SomeCard.inCard(BarChart(this.cTime(), '闸门调整次数统计')),
                  SomeCard.inCard(BarChart(this.cTime2(), '累计运行时间统计')),
                ]),
              ));
  }
}
